package fun.util.daohelper.springhibernate;

import fun.util.daohelper.DaoHelper;
import fun.util.daohelper.SpringUtils;
import fun.util.daohelper.junk.Junk;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;

/**
 * Author: bin
 * Date: Jan 23, 2006
 * Time: 9:25:13 PM
 */
public abstract class SpringHibernateDaoHelperBaseCase extends TestCase {

    private static final Logger logger = Logger.getLogger( SpringHibernateDaoHelperBaseCase.class );

    static String[] configs = {
            "classpath:spring/daoContext.xml",
            "classpath:spring/dataSourceContext.xml"
    };


    static FileSystemXmlApplicationContext appContext;

    static DaoHelper<Junk> daoHelper;

    static {
        appContext = new FileSystemXmlApplicationContext( configs );
        LocalSessionFactoryBean sessionBean = SpringUtils.getBean( appContext, LocalSessionFactoryBean.class );

        logger.info( "updating schema" );
        sessionBean.createDatabaseSchema();
        logger.info( "done update schema" );


        daoHelper = (DaoHelper<Junk>)appContext.getBean( "daoHelper" );
    }


    protected void setUp() throws Exception {

    }

    protected void tearDown() throws Exception {
        daoHelper.removeAll( Junk.class );
    }
}
